package com.jc.oss.config;

import com.jc.oss.adapter.StorageAdapter;
import com.jc.oss.adapter.AliyunStorageAdapter;
import com.jc.oss.adapter.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Description:
 * @Author: ASL_ly
 * @Package: com.jc.oss.config
 * @Project: jc-club
 * @Date: 2024/10/26  14:51
 */
@RefreshScope
@Configuration
public class StorageConfig {

    @Value(value = "${storage.service.type}")
    private String storageType;

    @Bean
    @RefreshScope
    public StorageAdapter storageAdapter(){
        if(storageType.equals("minio")){
            return new MinioStorageAdapter();
        } else if (storageType.equals("aliyun")) {
            return new AliyunStorageAdapter();
        }else {
            throw new IllegalArgumentException("未找到对应的文件存储处理器");
        }
    }
}
